package com.assignwork.modules.dailyshift;

import com.assignwork.dto.DailyShiftSearchDTO;
import com.assignwork.dto.DailyShiftSubmitDTO;
import com.assignwork.dto.VoyageCabinNodeSubmitDTO;
import com.assignwork.service.IDailyShiftService;
import com.assignwork.vo.DailyShiftVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName DailyShiftController
 * @Description 每日作业班组控制器
 * @Author dujianyu
 * @Date 2023/12/1 10:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("dailyShift")
public class DailyShiftController extends BladeController {

    private IDailyShiftService service;

    @PostMapping("generateDailyShift")
    @ApiOperationSupport(order = 0)
    @ApiOperation(value = "生成新的作业班次", notes = "")
    public R<Boolean> generateDailyShift() {
        return R.status(service.generateDailyShift());
    }

    @GetMapping("/page")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "分页", notes = "传入dto")
    public R<IPage<DailyShiftVO>> dailyShiftPage(DailyShiftSearchDTO dto, Query query) {
        return R.data(service.selectDailyShiftPage(dto, Condition.getPage(query)));
    }

    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "传入dto")
    public R<List<DailyShiftVO>> dailyShiftList(DailyShiftSearchDTO dto) {
        return R.data(service.selectDailyShiftList(dto));
    }

    @PostMapping("submit")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "修改", notes = "传入dto")
    public R<Boolean> submitDailyShift(@RequestBody DailyShiftSubmitDTO dto) {
        return R.status(service.submitDailyShift(dto));
    }

    @PostMapping("updateAssignLeader")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "修改调度主任", notes = "传入dto")
    public R<Boolean> updateAssignUser(@RequestBody DailyShiftSubmitDTO dto) {
        return R.status(service.updateAssignUser(dto));
    }

    @PostMapping("/remove")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "传入id")
    public R<Boolean> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
        return R.status(service.deleteLogic(Func.toLongList(id)));
    }

}
